import { AlmanacResponse } from '../types/almanac';
import { format } from 'date-fns';

export async function fetchAlmanacData(date: Date): Promise<AlmanacResponse> {
  const dateStr = format(date, 'yyyy-MM-dd');
  const response = await fetch(`https://www.36jxs.com/api/Commonweal/almanac?sun=${dateStr}`);
  if (!response.ok) {
    throw new Error('Failed to fetch almanac data');
  }
  
  return response.json();
}